package com.exrobot.module.rbt.service.robotoperationlog;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.exrobot.module.rbt.controller.admin.robotoperationlog.vo.*;
import com.exrobot.module.rbt.dal.dataobject.robotoperationlog.RobotOperationLogDO;
import com.exrobot.framework.common.pojo.PageResult;
import com.exrobot.framework.common.util.object.BeanUtils;

import com.exrobot.module.rbt.dal.mysql.robotoperationlog.RobotOperationLogMapper;

import static com.exrobot.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.exrobot.framework.common.util.collection.CollectionUtils.convertList;
import static com.exrobot.module.rbt.enums.ErrorCodeConstants.*;

/**
 * 车辆运行日志 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class RobotOperationLogServiceImpl implements RobotOperationLogService {

    @Resource
    private RobotOperationLogMapper robotOperationLogMapper;

    @Override
    public Long createRobotOperationLog(RobotOperationLogSaveReqVO createReqVO) {
        // 插入
        RobotOperationLogDO robotOperationLog = BeanUtils.toBean(createReqVO, RobotOperationLogDO.class);
        robotOperationLogMapper.insert(robotOperationLog);
        // 返回
        return robotOperationLog.getId();
    }

    @Override
    public void updateRobotOperationLog(RobotOperationLogSaveReqVO updateReqVO) {
        // 校验存在
        validateRobotOperationLogExists(updateReqVO.getId());
        // 更新
        RobotOperationLogDO updateObj = BeanUtils.toBean(updateReqVO, RobotOperationLogDO.class);
        robotOperationLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteRobotOperationLog(Long id) {
        // 校验存在
        validateRobotOperationLogExists(id);
        // 删除
        robotOperationLogMapper.deleteById(id);
    }

    @Override
        public void deleteRobotOperationLogListByIds(List<Long> ids) {
        // 删除
        robotOperationLogMapper.deleteByIds(ids);
        }


    private void validateRobotOperationLogExists(Long id) {
        if (robotOperationLogMapper.selectById(id) == null) {
            throw exception(RBT_DATA_NOT_EXISTS);
        }
    }

    @Override
    public RobotOperationLogDO getRobotOperationLog(Long id) {
        return robotOperationLogMapper.selectById(id);
    }

    @Override
    public PageResult<RobotOperationLogDO> getRobotOperationLogPage(RobotOperationLogPageReqVO pageReqVO) {
        return robotOperationLogMapper.selectPage(pageReqVO);
    }

}